<?php

//$db = mysql_connect('mysql14.rotondano.com.br','rotondano13','mmrProjetos@');
//mysql_select_db('rotondano13');
$db = mysql_connect('mysql07.rotondano.com.br','rotondano6','mmrProjetos@');
mysql_select_db('rotondano6');
mysql_query("SET NAMES 'utf8'");
mysql_query("SET character_set_connection=utf8");
mysql_query("SET character_set_client=utf8");
mysql_query("SET character_set_results=utf8");


$sql = sprintf("select campo,tipo,tamanho,label,linha,coluna,aba,lista from Page_mount where tabela = 'Cliente' order by script,linha,coluna");
$result = mysql_query($sql, $db);
if($result == 0)
{
     printf("Falha: %s\n", mysql_error($db));
     printf("%s\n", $sql);
     exit();
}
if(mysql_num_rows($result) > 0)
{
     $last = 'idcliente';
     while($myrow = mysql_fetch_row($result))
     {
          if($myrow[1] == 'date' || $myrow[1] == 'text')
          {
               $size = $myrow[1];
          }
          else if($myrow[1] == 'decimalX')
          {
               $size = sprintf("%s(%s,2)",strtoupper($myrow[1]),$myrow[2]);
          }
          else if($myrow[1] == 'enumx')
          {
               $last = $myrow[0];
               //continue;
          }
          else
          {
               $size = sprintf("%s(%s)",strtoupper($myrow[1]),$myrow[2]);
          }
          $comment = sprintf("%s;%s;%s;%s;%s;",$myrow[3],$myrow[4],$myrow[5],$myrow[6],$myrow[7]);
          $sql1 = sprintf("ALTER TABLE `Cliente` CHANGE COLUMN `$myrow[0]` `$myrow[0]` $size NOT NULL COMMENT '$comment' AFTER `$last`;");
          $last = $myrow[0];
          $result1 = 1;
          printf("<p>%s</p>",$sql1);
          $result1 = mysql_query($sql1, $db);
          if($result1 == 0)
          {
               printf("Falha: %s\n", mysql_error($db));
               printf("%s\n", $sql1);
               exit();
          }
     }
}
mysql_close($db);
?>
